import 'package:flutter/material.dart';
import 'package:lib_uikit/widgets/gt_popup_widget_v3.dart';

class GTPopupV3 {
  ///keyboardBottomHasMargin 键盘弹起是否整体向上移动 keyboardWidgetMargin: 键盘顶部和弹窗底部重合区域,防止太靠上
  static Future<dynamic> showPopup(BuildContext context,
      String title,
      Widget? contentView,
      String? startButtonText,
      String? endButtonText, {
        VoidCallback? onConfirmClick,
        VoidCallback? onCancelClick,
        VoidCallback? closeButtonClick,
        VoidCallback? closeDialogCallBack,
        bool? onlyExpandConfirm,
        bool? keyboardBottomHasMargin,
        double? keyboardWidgetMargin,
        ValueChanged<double>? heightCallBack,
        Widget? bottomWidget,
        bool? isMiniapp,
        bool? isDismissible,
      }) {
    return showModalBottomSheet(
      context: context,
      barrierColor: const Color.fromRGBO(0, 0, 0, 0.5),
      backgroundColor: Colors.transparent,
      isScrollControlled: true,
      isDismissible: isDismissible ?? true,
      builder: (context) {
        Widget contentWidget = GTPopupWidgetV3(
          title: title,
          heightCallBack: heightCallBack,
          contentView: contentView,
          startButtonText: startButtonText,
          endButtonText: endButtonText,
          onConfirmClick: onConfirmClick,
          onCancelClick: onCancelClick,
          onlyExpandConfirm: onlyExpandConfirm,
          closeClick: closeButtonClick,
          bottomWidget: bottomWidget,
          isMiniapp: isMiniapp,
        );
        double keyboardH = MediaQuery
            .of(context)
            .viewInsets
            .bottom;
        double keyboardHBigger = keyboardH - (keyboardWidgetMargin ?? 0);
        double paddingBottom = (keyboardH > 0) ? (keyboardHBigger > 0
            ? keyboardHBigger
            : keyboardH) : 0;
        return keyboardBottomHasMargin == true
            ? AnimatedPadding(
            padding: EdgeInsets.only(bottom: paddingBottom),
            duration: const Duration(milliseconds: 100),
            child: contentWidget)
            : contentWidget;
      },
    ).then((value) {
      // 关闭了
      closeDialogCallBack?.call();
    });
  }
}
